<?php
class model_rooms extends base_model
{
    public function mod_rooms_forSelect(){
        $sql = "SELECT `id`,`name` FROM `@@rooms` ORDER BY `sort` ASC";
        $data = $this->db->query($sql,3);
        $_result = array();
        foreach($data as $k=>$v) {
            $_result[$v['id']] = $v['name'];
        }
        return $_result;
    }
    public function mod_rooms_list($args){
        $where_txt = "";
        if(!empty($args['sKey'])){
            $where_txt .= " AND `title`='{$args['sKey']}'";
        }
        $sql = "SELECT ~field~ FROM `@@rooms` WHERE 1 {$where_txt} ~order~ ~limit~";
        //取出当前页的数据
        $sql_arr = array(
            'field' => '*',
            'page_current' => $args['page_current'],
            'pagesize' => $args['ps'],
            'order' => '',
        );
        $datas = $this->getTableRows($sql,$sql_arr);
        return array(
            'datas' => $datas['datas'],
            'record' => $datas['total'],
        );
    }
    public function mod_rooms_list_delete($id,$title){

    }
    public function mod_members_userLevel_forSelect(){
        $sql = "SELECT `lid`,`title` FROM `@@userlevel` ORDER BY `lid` ASC";
        $data = $this->db->query($sql,3);
        $_result = array();
        foreach($data as $k=>$v) {
            $_result[$v['lid']] = $v['title'];
        }
        return $_result;
    }
    public function mod_members_agentLevel_forSelect(){
        $sql = "SELECT `lid`,`title` FROM `@@agentlevel` ORDER BY `lid` ASC";
        $data = $this->db->query($sql,3);
        $_result = array();
        foreach($data as $k=>$v) {
            $_result[$v['lid']] = $v['title'];
        }
        return $_result;
    }
    # 聊天室黑名单
    public function mod_rooms_blacklist_list($args){
        $where_txt = "";
        if(!empty($args['sKey'])){
            $where_txt .= " AND l.`uno`='".$args['sKey']."'";
        }
        $sql = "SELECT ~field~ FROM `@@rooms_blacklist` l, `@@users` u,`@@rooms` g WHERE u.`uno`=l.`uno` AND g.`id`=l.`roomid` {$where_txt} ~order~ ~limit~";
        //取出当前页的数据
        $sql_arr = array(
            'field' => 'l.*,u.`nickname`,g.`name`',
            'page_current' => $args['page_current'],
            'pagesize' => $args['ps'],
            'order' => '',
        );
        $datas = $this->getTableRows($sql,$sql_arr);
        return array(
            'datas' => $datas['datas'],
            'record' => $datas['total'],
        );
    }
    # 聊天室白名单
    public function mod_rooms_whitelist_list($args){
        $where_txt = "";
        if(!empty($args['sKey'])){
            $where_txt .= " AND l.`uno`='".$args['sKey']."'";
        }
        $sql = "SELECT ~field~ FROM `@@rooms_whitelist` l, `@@users` u,`@@rooms` g WHERE u.`uno`=l.`uno` AND g.`id`=l.`roomid` {$where_txt} ~order~ ~limit~";
        //取出当前页的数据
        $sql_arr = array(
            'field' => 'l.*,u.`nickname`,g.`name`',
            'page_current' => $args['page_current'],
            'pagesize' => $args['ps'],
            'order' => '',
        );
        $datas = $this->getTableRows($sql,$sql_arr);
        return array(
            'datas' => $datas['datas'],
            'record' => $datas['total'],
        );
    }
}